/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.modelwalk.data');
(function () {
	
	var ymmDs = net.autodata.modelwalk.data.YearMakeModelDataStore.getInstance();
	
	var Proxy = Ext.extend(Ext.data.DataProxy, {
		constructor: function ()
		{
			Proxy.superclass.constructor.apply(this, arguments);
			var api = {};
			api[Ext.data.Api.actions.read] = true;
			Proxy.superclass.constructor.call(this, {api: api});
		},
		
		doRequest: function (action, rs, params, reader, callback, scope, options)
		{
			if (action !== 'read') {
				callback.call(scope || this, null, options, false);
			}
		
			if (this.fireEvent('beforeload', this, params) !== false) {
				this.processResponse(this.getRecords(params), reader, callback, scope, options);
			}
		},
		
		processResponse: function (response, reader, callback, scope, options)
		{
			try {
                var result = reader.readRecords(response);
            } catch (e) {
                this.fireEvent("loadexception", this, params, response, e);
                callback.call(scope || this, null, options, false);
                return;
            }
            
            this.fireEvent("load", this, response, options);
            callback.call(scope, result, options, true);
		},
		
		getRecords: Ext.emptyFn
	});
	
	
	var ModelYearProxy = Ext.extend(Proxy, {
		getRecords: function (params)
		{
			return ymmDs.getModelYears();
		}
	});
	net.autodata.modelwalk.data.ModelYearProxy = ModelYearProxy;
	
	var MakeProxy = Ext.extend(Proxy, {
		getRecords: function(params) 
		{
			return ymmDs.getMakes(params.modelYear);
		}
	});
	net.autodata.modelwalk.data.MakeProxy = MakeProxy;
	
	var ModelProxy = Ext.extend(Proxy, {
		getRecords: function (params)
		{
			return ymmDs.getModels(params.modelYear, params.makeCode);
		}
	});
	net.autodata.modelwalk.data.ModelProxy = ModelProxy;
	
})();